//
//  MainViewController.swift
//  微博001
//
//  Created by apple on 15/12/12.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    let mainTabBar = MainTabBar()

    override func viewDidLoad() {
        super.viewDidLoad()
        //tabBar 是只读属性  不能够直接进行设置 可以使用KVC 在运行时 间接赋值
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        setValue(mainTabBar, forKey: "tabBar")
        
   
        addChildViewControllers()
    }
    
    //PRIVATE 要保证监听方法的安全性,并且提高
   @objc private func composeBtnDidClick () {
        print(__FUNCTION__)
    let compose = ComposeTableViewController()
    let nav = UINavigationController(rootViewController: compose)
    
    //modla页面
    presentViewController(nav, animated: true, completion: nil)
    
    }
    
    //private 表示只能在本类中访问
    private func addChildViewControllers() {
    
        addChildViewControllerss(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
         addChildViewControllerss(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
         addChildViewControllerss(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
         addChildViewControllerss(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    
    private func addChildViewControllerss(vc:UIViewController,title:String,imageName:String){
        
        
//        let homeVC = HomeTableViewController()
//        let nav = UINavigationController(rootViewController: vc)
        let nav = BasNavViewController(rootViewController: vc)
        vc.title = "首页"
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
       
        
        
        
        addChildViewController(nav)

    }
}
